<!--
 * @Author: your name
 * @Date: 2021-02-08 15:25:14
 * @LastEditTime: 2021-04-03 23:22:43
 * @LastEditors: Please set LastEditors
 * @Description: 二级菜单
 * @FilePath: \jf-h5\src\page\main\view\cwrz.vue
-->
<template>
  <div class="tow-page">
    <div class="back" @click="$router.push('/')"></div>
    <van-loading v-if="loading" size="28" color="#0094ff" />
    <div v-else class="line-list">
      <line-text
        v-for="item in menu"
        :key="item.id"
        @click="toThreePage(item)"
        >{{ item.class_name }}</line-text
      >
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      menu: [],
      loading: true,
      isUrl: false
    };
  },
  created() {
    if (this.$route.meta.lineText) {
      this.isUrl = true;
      this.getUrlMenu();
      return;
    }
    this.getMenuTow();
  },
  methods: {
    // 获取url菜单
    async getUrlMenu() {
      this.loading = true;
      const { data } = await this.$api.realTime.getTowMenu();
      // this.menu = data.reverse();
      this.menu = data
      this.loading = false;
    },
    //去往三级菜单
    toThreePage({ id, have_son, type, class_name }) {
      if (this.isUrl) {
        this.$router.push({
          path: "/main/three-page",
          query: {
            cid: id,
            isUrl: this.isUrl
          }
        });
        true;
      }
      switch (have_son) {
        case 1:
          if (class_name == "监督信箱" && id == "4") {
            this.$router.push({
              path: "/main/supervise-email"
            });
            return;
          }
          this.$router.push({
            path: "/main/three-page",
            query: {
              cid: id,
              table_name: this.$route.meta.table_name + "_son"
            }
          });
          break;
        case 0:
          this.$router.push({
            path: "/detail",
            query: {
              class_name,
              type,
              table_name: this.$route.meta.table_name,
              id
            }
          });
          break;
      }
    },
    // 获取二级菜单列表
    async getMenuTow() {
      this.loading = true;
      const { code, data } = await this.$api.menu.getMenuTow({
        table_name: this.$route.meta.table_name
      });
      if (!code) {
        this.menu = data;
        this.loading = false;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.tow-page {
  .van-loading {
    text-align: center;
  }
  overflow: auto;
  padding-bottom: 50px;
  height: 100%;
  .back {
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 120px;
    background: url("/static/img/home/back-home.png") no-repeat center;
    background-size: 100%;
    // box-shadow: 0 5px 10px #474446;
    height: 35px;
    border-radius: 10px;
    // background-color: #1874b3;
    margin-top: 30px;
    margin-left: 30px;
    font-size: 30px;
    letter-spacing: 5px;
  }
  .line-list {
    display: flex;
    flex-direction: column;
    align-items: center;
    .line-text {
      margin-top: 50px;
      flex-shrink: 0;
    }
  }
}
</style>
